﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using Trackr.Helpers;

namespace Trackr.ViewModel
{
	public class SummaryViewModel<T> : BaseViewModel<T> where T :Window
	{
		private DateTime _currentDate = DateTime.Now;

		public SummaryViewModel(T view)
		{
			this.View = view;
		}
		#region properties
		public string Title
		{
			get
			{
				return "Trackr - Bobo";
			}
		}
		public DateTime CurrentDate
		{
			get { return _currentDate; }
			set
			{
				_currentDate = value;
				OnNotifyPropertyChanged(null);
			}
		}
		public TimeSpan TotalDuration
		{
			get
			{
				var timespans = TimeItems.Select(t => t.Duration);
				var ticks = timespans.Sum(t => t.Ticks);
				return new TimeSpan(ticks);
			}
		}

		public IEnumerable<Model.TimeItem> TimeItems
		{
			get
			{
				return Trackr.Core.Trackr.Instance.GetTimeItems(CurrentDate.Date, CurrentDate.Date.AddHours(23.9));
			}
		}
		#endregion properties
		#region commands
		public ICommand ShowPreviousDay
		{
			get
			{
				return Execute("ShowPreviousDay", (obj) =>
				{
					CurrentDate = CurrentDate.AddDays(-1);
				});
			}
		}
		public ICommand ShowNextDay
		{
			get
			{
				return Execute("ShowNextDay", (obj) =>
				{
					CurrentDate = CurrentDate.AddDays(1);
				});
			}
		}

		#endregion commands
	}
}
